Repository navigation
file viewer: a Copy action for the previewed file (#137) - #139
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The preview toolbar offered Download, Open and Share but no way to take the file's content, so copying meant opening the file elsewhere or dragging through the pane by hand. The Copy button appears only once the viewer has actually loaded text, and copies exactly the string that was fetched — the pane itself is escaped HTML. It also works for a remote project: the text is already in memory, so it never reaches /api/files/raw or /api/files/download, which is what issue #57 refuses and why Download and Share stay hidden there. Strings are added for all five languages the SPA ships.
7ecf870 to
550a83b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ecf870b8c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _fpvText = d.content || ''; | ||
| $i('fpvCopyBtn').style.display = _fpvText ? '' : 'none'; |
There was a problem hiding this comment.
Hide Copy when the API returns the oversized-file placeholder
For files larger than 2 MB, both the local /api/files handler and serveRemoteFiles() in server.js return [File too large to preview (>2 MB)] as content, rather than the file's text. This assignment treats that refusal as successfully loaded content, so Copy becomes visible, replaces the clipboard with the diagnostic string, and reports success. Exclude oversized-file responses from the copyable state so the action does not claim to copy file contents that were never fetched.
Useful? React with 👍 / 👎.
Fixes #137.
What this adds
A Copy action in the file preview toolbar, next to Download / Open / Share:
hidden for images, PDFs, binaries, refused reads and empty files — nothing to copy, nothing
to press;
copies as source;
copyText()helper, which already falls back to a hiddentextarea when
navigator.clipboardis unavailable (plain http over a LAN or tunnel);/api/files/rawor/api/files/download. Those are the endpoints issue Bug: File Browser Not Available for Remote SSH Projects #57 refuses, andthe reason Download and Share stay hidden for remote projects.
Copying a selection needs no new code — Ctrl/Cmd+C in the pane already does that, and the
new button deliberately copies the whole file.
Tests
test/file-preview-copy.test.js(added tonpm test) cuts the file-preview block out ofpublic/index.htmland runs it in a vm with a stubbedfetch,$i,toastand clipboard —no browser, no network. It checks the button's markup and default state, then: a text file
shows it and copies the fetched content, markdown copies its source, an empty file hides it
and copying is a no-op, binary/image/PDF previews and a refused read leave it hidden, closing
the viewer hides it and stops any copy, and reopening onto a failed read does not resurrect
the previous file's text.
Full local run on Node 24.22.1 (
npm test, CI=1): 93 steps, the new file 21/21, and the i18nparity suite 139/139 with the new keys in all five languages. Two steps went red in that run:
test/task-backlog.test.jsandtest/session-liveness.test.js. Both pass when run on theirown, and
task-backlogfails the same way on unmodifiedmain(measured on a clean worktreeof 2d95fe4) — pre-existing load-sensitive flakes, outside this change.